﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;

namespace SymulatorEthernetWPF.UserInterface.UIElements
{
    class NumberBox : TextBox
    {
        public NumberBox()
        {
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, null, CancelCommand));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, null, CancelCommand));
            TextAlignment = System.Windows.TextAlignment.Right;
        }

        public int Number
        {
            get { return Int32.Parse(this.Text); }
            set { this.Text = value.ToString(); }
        }

        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            int tmp;
            if (!Int32.TryParse(e.Text, out tmp))
                e.Handled = true;
        }

        private static void CancelCommand(object sender, CanExecuteRoutedEventArgs e)
         {
                    e.CanExecute = false;
                    e.Handled = true;
         }
    }
}